/*
 * @Author: szx
 * @Date: 2021-11-22 12:48:49
 * @LastEditTime: 2021-11-22 13:32:54
 * @Description:
 * @FilePath: \leetcode\1-99\17\17.js
 */
/**
 * @param {string} digits
 * @return {string[]}
 */

var letterCombinations = function (digits) {
    if (digits == '') {
        return [];
    }
    const number = new Map([
        ['2', 'abc'],
        ['3', 'def'],
        ['4', 'ghi'],
        ['5', 'jkl'],
        ['6', 'mno'],
        ['7', 'pqrs'],
        ['8', 'tuv'],
        ['9', 'wxyz']
    ]);
    const res = [];
    const dfs = function (index, str) {
        if (index == digits.length) {
            res.push(str);
        } else {
            const tmp = number.get(digits[index]);
            for (let t of tmp) {
                dfs(index + 1, str + t);
            }
        }
    };
    dfs(0, '');
    return res;
};
console.log(letterCombinations('23'));
